package com.example.emailcraft.config;

import com.example.emailcraft.interceptor.AuthInterceptor;
import com.example.emailcraft.interceptor.PermissionInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new AuthInterceptor())
                .addPathPatterns("/api/**")
                .excludePathPatterns("/api/v1/users/login",
                        "/api/v1/users/register",
                        "/api/v1/getJs",
                        "/api/v1/setCountdown",
                        "/api/v1/getCountdown",
                        "/*.html",
                        "/*.css",
                        "/*.js",
                        "/*.png",
                        "/*.jpg",
                        "/static/pc/**");

        registry.addInterceptor(new PermissionInterceptor())
                .addPathPatterns("/api/**");
    }
}
